//


import UIKit

class WP_BasicViewController: UIViewController {
    //声明一个属性myBlock，type为闭包可选类型
    //闭包类型：()->() ，无参数，无返回值 点击触发使用
    var myBlock:(()->())?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        // Do any additional setup after loading the view.
        self.navigationController?.navigationBar.barTintColor = UIColorFromHex(0xFFE4E1)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        
        setupLeftSetting()//调用
    }
    //标题
    func setNavTitle(_ text:String) {
        self.navigationItem.title = text
        self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 20),NSAttributedString.Key.foregroundColor:UIColor.black]
    }
    //返回键
    func setupLeftSetting() {
        if isShowLeftSetting() {//判断
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setBackgroundImage(UIImage(named: "back1"), for: .normal)
            button.addTarget(self, action: #selector(ddddd(click:)), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.leftBarButtonItem = leftV
        }
    }
    
    //back事件
    @objc func ddddd(click:UIButton) {
        self.navigationController?.popViewController(animated: true)
    }
    //MARK: 是否显示左键
    func isShowLeftSetting() -> Bool {
        return true
    }
    //youjian
    func setupRightSetting(_ obj:Any , myBlocks:@escaping (()->()))  {
        myBlock = myBlocks//点击触发
        if obj is String{
            
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setTitle(obj as? String, for: .normal)
            button.setTitleColor(UIColor.black, for: .normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
            button.addTarget(self, action: #selector(blockClick), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.rightBarButtonItem = leftV
            
        }else if  obj is UIImage {
            
            let button = UIButton(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
            button.setBackgroundImage(obj as? UIImage, for: .normal)
            button.addTarget(self, action: #selector(blockClick), for: .touchUpInside)
            let leftV:UIBarButtonItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.rightBarButtonItem = leftV
        }
        
    }
    // 右键点击事件
    @objc func blockClick() {
        if self.myBlock != nil {
            self.myBlock!()
        }
    }
    
    
    /// 状态栏样式 default lightContent
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    
    /// 状态栏是否隐藏
    override var prefersStatusBarHidden: Bool {
        return false
    }
    
    /// 状态栏的隐藏与显示动画样式
    override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
        return .slide
    }
    //随机数
    func randomNum() -> String {
        
        let count = 7
        let sourceString = "127893456"
        var re:String = String()
        
        for _ in 0..<count {
            let indexs = arc4random_uniform(UInt32(sourceString.count))
            let index1 = sourceString.index(sourceString.startIndex, offsetBy: indexs)
            print(index1)
            let index2 = sourceString.index(sourceString.startIndex, offsetBy: indexs+1)
            print(index2)
            let s = sourceString[index1 ..< index2]
            print(s)
            re += s
            print(re)
        }
        return re
    }
    
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
